package com.etrans.web.gps.business.Index.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.etrans.web.gps.base.service.BaseService;
import com.etrans.web.gps.business.Index.domain.IndexInfo;

@Service
public class IndexService extends BaseService{

	public int getAccessPlatfromCount(Map<String, Object> param) {
		return this.selectOne("indexQuery.queryPlatformCount", param);		
	}

	public Map<String, Object> getIndexInfo(Integer area_id) {
		Map<String, Object> result = new HashMap<String, Object>();
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("FullID",String.format("%08d",area_id) );
		int platCount = getAccessPlatfromCount(param);
		result.put("platCount", platCount);
		int vehicleCount = getVehicleCount(param);
		int netCount = getNetVehicleCount(param);
		result.put("vehicleCount", vehicleCount);
		result.put("netCount", netCount);
		double netRate=0.0;
		if(vehicleCount != 0){
			 netRate=netCount/(float)vehicleCount*100;
		}
		result.put("netRate", netRate);
		int entCount = getEnterpriseCount(param);
		result.put("enterpriseCount", entCount);
		return result;
	}

	public int getEnterpriseCount(Map<String, Object> param) {
		// TODO Auto-generated method stub
		return this.selectOne("indexQuery.getEnterpriseCount", param);
	}

	public int getNetVehicleCount(Map<String, Object> param) {
		return this.selectOne("indexQuery.getNetVehicleCount", param);
	}

	public int getVehicleCount(Map<String, Object> param) {
		return this.selectOne("indexQuery.getVehicleCount", param);
	}

	public List<Map<String, Object>> getPlatformStatus(Integer area_id) {
		// TODO Auto-generated method stub
		Map<String, Object> param = new HashMap<>();
		param.put("FullID", String.format("%08d", area_id));
		return this.selectList("indexQuery.getPlatformStatus", param);
	}

	public List<IndexInfo> getAreaInfo(Map<String,Object> map) {
		return this.selectList("indexQuery.getAreaInfo", map);
	}


	public IndexInfo getStatisticsByArea(IndexInfo info, Integer area_id) {
		Map<String,Object> param = new HashMap<>();
		param.put("AreaID", String.format("%08d",info.getAreaId()));
		param.put("UAreaID", String.format("%08d", area_id));
		int enterpriseCount = this.selectOne("indexQuery.getEnterpriseByArea", param);
		info.setEnterpriseCount(enterpriseCount);
		return info;
	}
	
	public List<String> getVehicleByArea(IndexInfo info, Integer area_id){

		Map<String,Object> param = new HashMap<>();
		param.put("AreaID", String.format("%08d",info.getAreaId()));
		param.put("UAreaID", String.format("%08d", area_id));
		List<String> list = this.selectList("indexQuery.getVehicleByArea", param);
		return list;
		
	}

	public List<IndexInfo> getTradeInfo() {
		// TODO Auto-generated method stub
		
		return this.selectList("indexQuery.getTradeInfo", null );
	}


	public List<Map<String, Object>> getVehicleByTrade(IndexInfo info, Integer area_id) {
		// TODO Auto-generated method stub
		HashMap<String, Object> param = new HashMap<>();
 		param.put("FullID", String.format("%08d", area_id));
 		param.put("tradeId", info.getTradeId());
		return this.selectList("indexQuery.getVehicleByTrade", param);
	}
	//查询入网车辆BYrole
	public List<HashMap<String, Object>> getNetVehicle(HashMap<String, Object> params) {
		
		return this.selectList("indexQuery.getNetVehicle", params);
	}
	
	public List<Map<String, Object>> getVehicleByTradeAll(IndexInfo info, Integer area_id) {
		// TODO Auto-generated method stub
		HashMap<String, Object> param = new HashMap<>();
 		param.put("FullID", String.format("%08d", area_id));
 		param.put("tradeId", info.getTradeId());
		return this.selectList("indexQuery.getVehicleByTradeAll", param);
	}

}
